package com.xhsj.user.hr.process.processDefinition.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xhsj.user.hr.process.processDefinition.entity.TbGlobalApprovalHiTask;
import com.xhsj.user.hr.process.processDefinition.service.TbGlobalApprovalHiTaskService;
import com.xhsj.user.utils.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//import org.springframework.security.access.prepost.PreAuthorize;


/**
 * <p>
 * 流程-历史表 前端控制器
 * </p>
 *
 * @author liuqinghua
 * @since Aug 31, 2020 5:17:39 PM
 */
@Slf4j
@Api(tags = "流程-历史表")
@RestController
@RequestMapping("/process/tbGlobalApprovalHiTask")
public class TbGlobalApprovalHiTaskController {

	@Autowired
    public TbGlobalApprovalHiTaskService service;


	/**
	 * 保存/修改
	 * @author liuqinghua
	 * @date Aug 31, 2020 5:17:39 PM
	 */
	@ApiOperation(value = "流程-历史表,保存/修改", notes = "流程-历史表,保存和修改方法")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
    // @PreAuthorize("hasAuthority('tb:global:approval:hi:task:edit')")
	public Message save(@RequestBody TbGlobalApprovalHiTask data){
    	try {
    		service.save(data);
			return Message.success("成功");
		} catch (Exception e) {
			log.error("保存失败:{}",e);
        	return Message.error(1,"失败");
		}

	}

	/**
	 * 通过id删除数据
	 * @author liuqinghua
	 * @date Aug 31, 2020 5:17:39 PM
	 */
	@ApiOperation(value = "流程-历史表删除", notes = "通过id删除流程-历史表信息。")
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
    // @PreAuthorize("hasAuthority('tb:global:approval:hi:task:delete')")
	public Message delete(@RequestParam(value="id") String id) {
		try {
			service.removeById(id);
        	return Message.success("成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
            return Message.error(1,"失败");
		}

	}

	/**
	 * 批量删除
	 * @author liuqinghua
	 * @date Aug 31, 2020 5:17:39 PM
	 */
	@ApiOperation(value = "批量删除", notes = "批量删除。")
	@RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
	public Message batchDelete(@RequestBody List<String> list) {
		try {
			service.removeByIds(list);
    		return Message.success("成功");
		} catch (Exception e) {
    		log.error("删除失败:{}",e);
    		return Message.error(1,"失败");
		}
    }


    /**
    * 通过id获取实体类
    * @author liuqinghua
    * @date Aug 31, 2020 5:17:39 PM
    */
	@ApiOperation(value = "通过id获取流程-历史表实体类", notes = "通过id获取流程-历史表实体类。")
	@RequestMapping(value="/getById",method = RequestMethod.GET)
    // @PreAuthorize("hasAuthority('tb:global:approval:hi:task:view')")
	public Message getById(@RequestParam(value="id") String id) {
    	return Message.success("成功",service.getById(id));
	}

    /**
    * 通过id查询详细信息
    * @author liuqinghua
    * @date Aug 31, 2020 5:17:39 PM
    */
	@ApiOperation(value = "通过id获取实体类详细信息", notes = "通过id获取实体类详细信息。")
	@RequestMapping(value="/detail",method = RequestMethod.GET)
    // @PreAuthorize("hasAuthority('tb:global:approval:hi:task:view')")
	public Message detail(@RequestParam(value="id") String id) {
    	return Message.success("成功",service.getById(id));
	}

	/**
	 * 历史记录与意见
	 * @author liuqinghua
	 * @date Aug 31, 2020 5:17:39 PM
	 */
	@ApiOperation(value = "历史记录与意见", notes = "历史记录与意见。")
	@RequestMapping(value="/getApprovalHiTaskList",method = RequestMethod.GET)
	public Message getApprovalHiTaskList(@RequestParam(value="dataId") Long dataId,@RequestParam(value="businessId") Long businessId) {
		return Message.success("成功",service.getApprovalHiTaskList(dataId,businessId));
	}

}

